package com.budwk.app.miniapp.common;


import lombok.extern.slf4j.Slf4j;
import org.nutz.integration.jedis.pubsub.PubSub;
import org.nutz.integration.jedis.pubsub.PubSubService;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.json.Json;
import org.nutz.lang.Strings;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author wizzer@qq.com
 */
@IocBean(create = "init")
@Slf4j
public class PubSubTest implements PubSub {
    @Inject
    private PubSubService pubSubService;
    @Inject
    private RedissonClient redissonClient;


    public void init() {
        pubSubService.reg("wk:test:subscribe", this);
    }

    @Override
    public void onMessage(String channel, String message) {
        if (!channel.equalsIgnoreCase("wk:test:subscribe")) {
            return;
        }
//        List<Sys_user> list = Json.fromJsonAsList(Sys_user.class, message);
//
//        list.parallelStream().forEach(System.out::println);
        // 多实例会收到重复的多条,只需插入一条即可
        try {
//            RLock rLock = redissonClient.getLock(RedisConstant.JOB_HISTORY + jobInfo.getTaskId());
//            if (rLock.tryLock(3, TimeUnit.SECONDS)) {
//
//            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}
